﻿using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using WYJCore;
using WYJCore.Extension;
using WYJCore.Web;
using WYJData.DatabaseAccess;
using WYJData.Orm;
using WYJWeb.Models;

namespace WYJWeb
{
    public class TestController
    {
        public HttpContext CurrentHttpContext;
        private void UnitTest()
        {
            var test = new Test() { Id = 1, UnitName = "Table.GetUpdateSql()", TestTime = DateTime.Today };
            var sql = new Table(typeof(Test)).GetUpdateSql(test);
            test.Result = sql;
            ConsoleCenter.UnitTestResult.Add(test);
        }

        public Response GetList(int pageIndex, int pageSize, string key)
        {
            UnitTest();
            var index = (pageIndex-1) * pageSize;
            var Count = ConsoleCenter.UnitTestResult.Count;

            if (pageSize >= Count - index) pageSize = Count - index;
            return new Response
            {
                Data = new
                {
                    Count,
                    List = ConsoleCenter.UnitTestResult.GetRange(index, pageSize)
                }
            };
        }

        public object GetUser()
        {
            var db = new Database();
            var u = 
            db.GetModel<Test>(x => x.Id == 1);
            return u;
        }
    }
}
